// pages/refund/refund.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
     flag:false,
     cause:'退款原因' ,
     text:{},
    typeInfo:[],
     selcont:"请选择",
     order:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    httpUtil.getHttp("/search/get/text"
      , { id: 10 }, function (res) {
        //将markdown内容转换为towxml数据
        let data = app.towxml.toJson(res.text, 'markdown');
        that.setData({
          text: data
        })
      })
    httpUtil.getHttp("/goods_travel/get/dict"
      , { name: "refund_type" }, function (res) {
         var typeInfo = [];
        for (var i = 0; i < res.length; i++) {
          typeInfo.push(res[i].code);
        }
        that.setData({
          typeInfo: typeInfo
        })
      })
 
    that.getOrder(options.orderNumber);
  },
  getOrder: function (orderNumber){
    var that = this; 

    httpUtil.getHttp("/order/get"
      , {
        orderNumber: orderNumber }, function (res) {
    
        that.setData({
          order: res
        })
      }) 
  },
  addRefund:function(e){
    var that = this; 
    var cause = that.data.cause;
    if (cause =='退款原因'){
      wx.showToast({
        title: '请选择退款原因',
        icon: 'loading',
        duration: 1000,
        mask: true
      })
      return;
    }
    httpUtil.getHttp("/order/addRefund"
      , {
        orderNumber: that.data.order.orderNumber,
        text: cause
      }, function (res) {
 
        wx.navigateBack();

      }) 

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  closeWicket:function(){
     this.setData({
       flag: false 
     })
  },
  selItem:function(){
    this.setData({
      flag: true
    })
  },
  radioChange:function(e){
    console.log(e)
    var detail = e.detail.value;
    this.setData({
      cause:detail,
      flag: false,
      selcont: "已选择" 
    })
  }
})